<!--
  @Descripttion:：项目卡片
  @Date：2023年03月04日 01:54:38
-->
<template>
  <section class="pc-product-card" @click="openDetail">
    <div class="base-info">
      <p class="title">{{ data.title }}</p>
      <div class="desc" v-html="data.projectDescription"></div>
    </div>
    <div class="row">
      <div class="source">{{ data.projectTypeName }}</div>
      <div class="release-date">发布日期：{{ data.releaseTime }}</div>
    </div>
    <div class="row2">
      <div class="source-from">
        <span>举办单位</span>
        <img :src="data.holdUnitUrl" alt="举办单位" srcset="" />
      </div>
      <div :class="['btn', {'isEnd': statusStr === '已结束'|| statusStr === '已报名' || statusStr === '未开始'}]">{{ statusStr || "--" }}</div>
    </div>
  </section>
</template>

<script>
import moment from 'moment'
export default {
  name: "pcProductItem",
  components: {},
  // 组件状态值
  data() {
    return {
    };
  },
  props: {
    data: {
      type: Object,
    },
  },
  // 计算属性
  computed: {
    statusStr () {
        let endTime = moment(this.data.endTime, "YYYY-MM-DD HH:mm:ss")
            let startTime = moment(this.data.startTime, "YYYY-MM-DD HH:mm:ss")
            let currentTime =  moment()
        if (!this.data.scheduleType && currentTime.isBefore(startTime)) {
            return '未开始'
        } else if (Number(this.data.scheduleType) === 1) {
            if(Number(this.data.entryFlag) === 1){
                // entryFlag 1:已报名; 其他为未报名
                return '已报名'
            } else if (currentTime.isBefore(endTime) && startTime.isBefore(currentTime)) {
                return '可报名'
            } else {
                return '已结束'
            }
        } else  {
            return '已结束'
        }
    }
  },
  // 侦听器
  watch: {},
  // 组件方法
  methods: {
    openDetail() {
      if (this.data?.id) {
        this.$router.push({
          name: "productDetail",
          query: {
            id: this.data.id,
          },
        });
      }
    },
  },
  created() {},
  mounted() {
  },
};
</script>
<!-- Add "scoped" attribute to limit CSS to this component only -->
<style lang="less" scoped>
.pc-product-card {
  width: 100%;
  height: 311px;
  margin: 0 30px 30px 0;
  background: #ffffff;
  box-shadow: 0px 2px 12px 0px #e2e3e5;
  border-radius: 6px;
  border: 1px solid #d4d6da;
  cursor: pointer;
  .base-info {
    width: 100%;
    height: 187px;
    background: linear-gradient(
      146deg,
      rgba(211, 229, 249, 0.6) 0%,
      #fbfcfc 100%
    );
    border: 1px solid rgba(212, 214, 218, 0.6);
    padding: 25px 25px 20px;
    .title {
      width: 100%;
      max-height: 66px;
      font-size: 22px;
      font-family: PingFangSC-Medium, PingFang SC;
      font-weight: 500;
      color: #37383d;
      line-height: 33px;
      margin-bottom: 20px;
      overflow: hidden;
      text-overflow: ellipsis;
      display: -webkit-box;
      -webkit-line-clamp: 2;
      -webkit-box-orient: vertical;
    }
    .desc {
      font-size: 16px;
      font-family: PingFangSC-Regular, PingFang SC;
      font-weight: 400;
      color: #9597a0;
      line-height: 28px;
      width: 100%;
      max-height: 56px;
      overflow: hidden;
      text-overflow: ellipsis;
      display: -webkit-box;
      -webkit-line-clamp: 2;
      -webkit-box-orient: vertical;
    }
  }

  .row {
    position: relative;
    width: 100%;
    height: 64px;
    display: flex;
    flex-flow: row nowrap;
    justify-content: space-between;
    align-items: center;
    padding: 0 25px 0 20px;
    border-bottom: 1px solid rgba(212, 214, 218, 0.6);
    .source {
      height: 34px;
      line-height: 34px;
      padding: 0 15px;
      background: rgba(255, 255, 255, 0.49);
      border-radius: 17px;
      border: 1px solid #3d6cb0;
      font-size: 16px;
      font-family: PingFangSC-Medium, PingFang SC;
      font-weight: 500;
      color: #3d6cb0;
    }
    .release-date {
      font-size: 16px;
      font-family: PingFangSC-Regular, PingFang SC;
      font-weight: 400;
      color: #9597a0;
      line-height: 28px;
    }
  }
  .row2 {
    position: relative;
    width: 100%;
    height: 59px;
    display: flex;
    flex-flow: row nowrap;
    justify-content: space-between;
    align-items: center;
    padding: 0 0 0 20px;
    .source-from {
      display: flex;
      flex-flow: row nowrap;
      justify-content: flex-start;
      align-items: center;
      span {
        font-size: 14px;
        font-family: PingFangSC-Regular, PingFang SC;
        font-weight: 400;
        color: #9597a0;
        line-height: 28px;
        margin-right: 12px;
      }
      img {
        display: inline-block;
        height: 39px;
      }
    }
    .btn {
      width: 190px;
      height: 100%;
      background: #4677b9;
      border-radius: 0px 0px 6px 0px;
      display: flex;
      flex-flow: row nowrap;
      justify-content: center;
      align-items: center;
      font-size: 20px;
      font-family: PingFangSC-Semibold, PingFang SC;
      font-weight: 600;
      color: #ffffff;
    }
    .isEnd {
        background: #e3e3e3;
    }
  }
}
</style>
